class Comment < ActiveRecord::Base
  belongs_to            :user
  belongs_to            :photo
  belongs_to            :video
  belongs_to            :show
  belongs_to            :song
  belongs_to            :blog_post
  validates_presence_of :user
  validates_presence_of :text
  validate              :belongs_to_something
  validate              :belongs_to_only_one_thing
  validate              :not_too_long
  
  def not_too_long
    self.errors.add(:text, "Your comment is pretty long... short and sweet please.") if self.text.length >= 250
  end
  
  def belongs_to_something
    (!self.photo.nil? || !self.video.nil? || !self.show.nil? || !self.song.nil? || !self.blog_post.nil?) ? (return true) : (return false)
  end
  
  def belongs_to_only_one_thing
    ((self.video && self.photo) || (self.video && self.song) || (self.video && self.show) || (self.photo && self.show) || (self.photo && self.song) || (self.show && self.song) || (self.show && self.blog_post) || (self.song && self.blog_post) || (self.video && self.blog_post) || (self.photo && self.blog_post)) ? (return false) : (return true)
  end
  
  def authorized_to_modify?(current_user)
    (current_user == self.user) ? (return true) : (return false)
  end
  
  def for_a?
    (return "photo")      if self.photo
    (return "video")      if self.video
    (return "song")       if self.song
    (return "show")       if self.show
    (return "blog_post")  if self.blog_post
  end
  
  def for_video?
    self.video ? (return true) : (return false)
  end
  
  def for_photo?
    self.photo ? (return true) : (return false)
  end
  
  def for_show?
    self.show ? (return true) : (return false)
  end
  
  def for_song?
    self.song ? (return true) : (return false)
  end
  
  def for_blog_post?
    self.blog_post ? (return true) : (return false)
  end
end
